package com.baomidou.springwind.controller.supply;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.kisso.annotation.Permission;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springwind.controller.BaseController;
import com.baomidou.springwind.entity.*;
import com.baomidou.springwind.enums.NodeTypeEnum;
import com.baomidou.springwind.pojo.DrivingRoute;
import com.baomidou.springwind.pojo.Test;
import com.baomidou.springwind.service.CityOrderService;
import com.baomidou.springwind.service.NetworkCandidateService;
import com.baomidou.springwind.service.ProjectService;
import com.baomidou.springwind.service.WeekOrderService;
import com.baomidou.springwind.service.NetworkDepotService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.DecimalFormat;
import java.util.*;

/**
 * <p>
 * 网络规划：第二次统计分析
 * </p>
 *
 * @Author huangtao
 * @Date 2017-8-21
 */
@Controller
@RequestMapping("/network/supply")
public class OrderAnalysisController extends BaseController {

    @Autowired
    private CityOrderService cityOrderService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private NetworkCandidateService networkCandidateService;
    @Autowired
    private NetworkDepotService networkDepotService;

    /**
     * 第二次统计分析
     */
    @RequestMapping("/orderAnalysis")
    @Permission("1001")
    public String response(Model model){
       /* EntityWrapper<NetworkCost> wrapper = new EntityWrapper<NetworkCost>();
        wrapper.eq("batch_id",getProjectId());
        wrapper.eq("type1", 2);
        model.addAttribute("prjList", networkDepotDao.selectList(wrapper));
        */
        return pjaxPath("/lpp/network/supply/orderAnalysis/main", model);
    }

    /**
     * 第二次统计分析数据展示
     * @return
     */
    @ResponseBody
    @RequestMapping("/orderAnalysis/getAllData")
    @Permission("1001")
    public String getAllData() {
        JSONObject ret=new JSONObject();
        EntityWrapper<NetworkDepot> wrapper = new EntityWrapper<NetworkDepot>();
        wrapper.eq("batch_id",getProjectId());
        wrapper.eq("type",0);
        wrapper.eq("depot_level",1);
        List<NetworkDepot> depotList = networkDepotService.selectList(wrapper);
        JSONArray array0 = new JSONArray();
        JSONArray array1 = new JSONArray();
        JSONArray array2 = new JSONArray();
        JSONArray array3 = new JSONArray();
        JSONArray array4 = new JSONArray();
        JSONArray array5 = new JSONArray();
        JSONArray array6 = new JSONArray();
        for (int i=0;i<depotList.size();i++){
            EntityWrapper<NetworkDepot> wrapper1 = new EntityWrapper<NetworkDepot>();
            wrapper1.eq("batch_id",getProjectId());
            wrapper1.eq("depot_level",2);
            wrapper1.eq("p_id",depotList.get(i).getId());
            List<NetworkDepot> depotList1 = networkDepotService.selectList(wrapper1);
            array0.add(depotList.get(i).getDepotName());
            array1.add(depotList1.size());
            array2.add(depotList.get(i).getDepotCapacity());
            array3.add(depotList.get(i).getDepotRent());
            array4.add(depotList.get(i).getWorkerCost());
            array5.add(depotList.get(i).getDeviceCost());
            array6.add(depotList.get(i).getEnergyCost());
        }
        ret.put("arr0",array0);
        ret.put("arr1",array1);
        ret.put("arr2",array2);
        ret.put("arr3",array3);
        ret.put("arr4",array4);
        ret.put("arr5",array5);
        ret.put("arr6",array6);
        return callbackSuccess(ret);
    }

}
